/* Historial
 *
 */

package edu.umss.arqui10.modelo;

import java.io.Serializable;
import javax.persistence.Id;
import javax.persistence.Column;
import javax.persistence.Table;

import java.util.Date;
import java.util.TreeMap;
import javax.persistence.Temporal;
/** Historial
 *
 * @author rho1and0
 */

@Table(name="History")
 class History implements Serializable {

    @Column(name="history_date")
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date date;
    private TreeMap<Date, Registry> registry;
    @Id
    private Long id;
    Pair algo;

    public History() {
        this.date = new Date();
        this.registry = new TreeMap<Date, Registry>();
    }

    public void updateDate(){
        this.date = new Date();
    }

    public Date getDate() {
        return date;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    int registrySize() {
        return this.registry.size();
    }

    void openRegistry(String antecedent) {
        this.registry.put(new Date(), new Registry(antecedent));
    }

    Registry getOpenRegistry() {
        Registry res = this.registry.get(this.registry.lastKey());
        if(!res.isOpen()) {
            res = null;
        }
        return res;
    }

    public TreeMap<Date, Registry> getAllRegistry() {
        throw new UnsupportedOperationException("Not yet implemented");
    }

    void assignService(Service serv) {
        Registry openRegistry = this.getOpenRegistry();
        openRegistry.assignService(serv);
    }
}